package com.testone.controller;

import com.testone.entity.UserEntity;
import com.testone.jpa.UserJPA;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserJPA userJPA;

    /**
     * 查询用户信息
     * @return
     */
    @RequestMapping(value = "/list" , method = RequestMethod.GET)
    public List<UserEntity> list(){
        return userJPA.findAll();
    }

    /**
     * 添加用户
     * @param userEntity
     * @return
     */
    @RequestMapping(value = "/save" , method = RequestMethod.GET)
    public UserEntity save(UserEntity userEntity){
        return userJPA.save(userEntity);
    }

    @RequestMapping(value = "/delete" , method = RequestMethod.GET)
    public List<UserEntity> delete(Long id){
        userJPA.delete( id );
        return userJPA.findAll();
    }


}